package com.sofwin.ruoyi.scyffinal.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.api.domain.SysFile;
import com.ruoyi.system.api.domain.SysUser;

import com.sofwin.ruoyi.scyffinal.dto.RiskUserDeptDto;
import com.sofwin.ruoyi.scyffinal.pojo.RiskControlNoticeCard;

import com.sofwin.ruoyi.scyffinal.remote.SysFileService;
import com.sofwin.ruoyi.scyffinal.remote.SysPostService;
import com.sofwin.ruoyi.scyffinal.remote.SysUserService;
import com.sofwin.ruoyi.scyffinal.service.RiskControlNoticeCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/riskControlNoticeCard")
public class RiskControlNoticeCardController extends BaseController {
    @Autowired
    private RiskControlNoticeCardService riskControlNoticeCardService;
    @Autowired
    private SysFileService sysFileService;
    @Autowired
    private SysPostService sysPostService;
    @Autowired
    private SysUserService sysUserService;

    /**
     * 列表，精确查询，迷糊查询
     * @param riskControlNoticeCard
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(RiskControlNoticeCard riskControlNoticeCard) {
        startPage();
        List<RiskUserDeptDto> list = riskControlNoticeCardService.riskUserDeptDtoList(riskControlNoticeCard);
        return getDataTable(list);
    }

    /**
     * 新增RiskControlNoticeCard
     * @param riskControlNoticeCard
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody RiskControlNoticeCard riskControlNoticeCard){
        riskControlNoticeCardService.save(riskControlNoticeCard);
        return AjaxResult.success();
    }

    /**
     * 批量删除
     * @param riskIds
     * @return
     */
    @DeleteMapping("{riskIds}")
    public AjaxResult remove(@PathVariable Long[] riskIds){
        riskControlNoticeCardService.removeByIds(Arrays.asList(riskIds));
        return AjaxResult.success();
    }

    /**
     * 通过riskId获取精确数据
     * @param riskId
     * @return
     */
    @GetMapping(value = "{riskId}")
    public AjaxResult getInfo(@PathVariable Long riskId){
        System.out.println(riskId);
        RiskControlNoticeCard riskControlNoticeCard =new RiskControlNoticeCard();
        riskControlNoticeCard.setRiskId(riskId);
        List<RiskUserDeptDto> riskUserDeptDtos =
                riskControlNoticeCardService.riskUserDeptDtoList(riskControlNoticeCard);
        RiskUserDeptDto riskUserDeptDto = riskUserDeptDtos.get(0);
        return AjaxResult.success(riskUserDeptDto);
    }

    /**
     * 更新数据
     * @param riskControlNoticeCard
     * @return
     */
    @PutMapping
    public AjaxResult update(@RequestBody RiskControlNoticeCard riskControlNoticeCard){
        riskControlNoticeCardService.updateById(riskControlNoticeCard);
        return AjaxResult.success();
    }

    /**
     * 远程服务调用
     * 获取岗位列表
     * @return
     */
    @GetMapping("/post/list")
    public TableDataInfo getPostList(){
        return sysPostService.list();
    }

    /**
     * 远程服务调用
     * 获取责任人列表
     * @return
     */
    @GetMapping("/user/list")
    public TableDataInfo getUserList(){
        return sysUserService.list();
    }
}
